<template>
  <div>
    <el-drawer :visible.sync="drawer" direction="rtl" size="50%" :with-header="false">
      <div class="drawer_box">
        <div class="drawer_t">
          <div class="drawer_t_l">
            <img class="drawer_t_l_img" src="/static/skin/herodoo/main/platform/home/img/quanyishaixuan.png" alt="" />
            {{ isEdit ? "查看" : "创作" }}精品权益
          </div>
          <img class="drawer_t_r" src="/static/skin/herodoo/main/platform/home/img/guanbi.png" alt=""
            @click="drawer = false" />
        </div>

        <div class="block">
          <!-- 权益组合 -->
          <div class="content-box">
            <div class="title">
              权益组合
              <el-tooltip placement="bottom-start">
                <div slot="content">
                  权益选择规则:<br />
                  1、自有权益选择数+已购买权益选择数必须大于等于2<br />
                  2、若未选择已购买权益，则自有权益选择数必须大于等于2<br />
                  3、至少选择一个自由权益
                </div>
                <i class="el-icon-warning-outline"></i>
              </el-tooltip>
            </div>
            {{ initData.ownList.options[0] }}
            <div class="list-box" v-if="initData.ownList.options.length > 0">
              <div class="left">已选自有权益:</div>
              <div class="right">
                <div style="display:flex;width: 100%;" v-for="(item, i) in initData.ownList.options" :key="item.id">
                  <div class="list1">
                    <div class="item1" v-if="!isEdit">
                      <i @click="removeOwnlist(item.id, i)" class="el-icon-remove"
                        style="color:#ED5757;font-size: 3rem;"></i>
                    </div>
                  </div>
                  <div
                    style="padding:1.3rem;background: #FFFFFF;box-shadow: 2px 1px 9px 0px rgba(180,171,206,0.25);border-radius: 18px 18px 18px 18px;width: 100%;margin-bottom: 1.3rem;">
                    <div class="list">
                      <div class="item">
                        <div style="width: 30%;height: 100%;margin-right: 2%;">
                          <img style="width: 100%;height: 100%;border-radius: 8px;"
                            :src="JSON.parse(item.MainPicturePath)[0].url"
                            :alt="JSON.parse(item.MainPicturePath)[0].name" />
                        </div>
                        <div style="display: flex;flex-direction: column;justify-content: space-between;width:68%;">
                          <div>
                            <p style="font-size:2rem;color:#1E1B19;line-height:3rem;font-weight: 600;">
                              {{ item.Name }}
                            </p>
                            <div>
                              <span v-for="item1 in getTag(item.EquityFlagListName)"
                                style="padding:4px;border-radius: 2px 2px 2px 2px;border:1px solid #426CE9;display:inline-block; font-size:1rem;line-height:1rem;color:#426CE9;margin-right: 0.4rem;">{{
                                  item1 }}</span>
                            </div>
                            <div style="color:#1E1B19;">
                              <span style="color: #EC5D31;padding-right: 10px;">单价：￥{{ item.CostPrice }}</span>
                              数量：x{{ item.num }}
                            </div>
                          </div>
                          <div style="display: flex;justify-content: space-between;">
                            <div>
                              <span style="font-size:1.2rem;color:#827070;margin-right:2rem;">库存：{{
                                item.InventoryQuantity }}份</span>
                              <span style="font-size:1.2rem;color:#827070;margin-right:2rem;">已售：{{ item.SoldQuantity
                                }}份</span>
                            </div>
                            <div style="font-size: 2.5rem;font-weight: bold;color: #EC5D31;">
                              总价：￥{{
                                (item.CostPrice * item.num).toFixed(2)
                              }}
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>

                <span class="warning_tip"
                  v-if="portfolioBenefits.length > 1 ? false : true || initData.ownList.options.length < 1">您当前选择的权益与组合规则不符，请按照组合规则选择，鼠标悬浮在<i
                    class="el-icon-warning-outline" style="color:black;"></i>上查看组合规则。</span>
              </div>
            </div>

            <div class="list-box" v-if="!isEdit">
              <div class="left">自有权益:</div>
              <div class="right">
                <div class="add_content" @click="openChildDrawer('ownList', 1)">
                  <i class="el-icon-plus"></i>
                  <span>点击添加权益</span>
                </div>
              </div>
            </div>

            <div class="list-box" v-if="initData.purchasedList.options.length > 0">
              <div class="left">已选已购权益:</div>
              <div class="right">
                <div style="display:flex;width: 100%;" v-for="(item, i) in initData.purchasedList.options"
                  :key="item.id">
                  <div class="list1" v-if="!isEdit">
                    <div class="item1">
                      <i @click="removePurchasedList(item.ID, i)" class="el-icon-remove"
                        style="color:#ED5757;font-size: 3rem;"></i>
                    </div>
                  </div>
                  <div
                    style="padding:1.3rem;background: #FFFFFF;box-shadow: 2px 1px 9px 0px rgba(180,171,206,0.25);border-radius: 18px 18px 18px 18px;width: 100%;margin-bottom: 1.3rem;">
                    <div class="list">
                      <div class="item">
                        <div style="width: 30%;height: 100%;margin-right: 2%;">
                          <img style="width: 100%;height: 100%;border-radius: 8px;"
                            :src="JSON.parse(item.MainPicturePath)[0].url"
                            :alt="JSON.parse(item.MainPicturePath)[0].name" />
                        </div>
                        <div style="display: flex;flex-direction: column;justify-content: space-between;width:68%;">
                          <div>
                            <p style="font-size:2rem;color:#1E1B19;line-height:3rem;font-weight: 600;">
                              {{ item.Name }}
                            </p>
                            <div>
                              <span v-for="item1 in getTag(item.EquityFlagListName)" :key="item1"
                                style="padding:4px;border-radius: 2px 2px 2px 2px;border:1px solid #426CE9;display:inline-block;
                                                        font-size:1rem;line-height:1rem;color:#426CE9;margin-right: 0.4rem;">{{ item1 }}</span>
                            </div>
                            <div style="color:#1E1B19;">
                              <span style="color: #EC5D31;padding-right: 10px;">单价：￥{{ item.CostPrice }}</span>
                              数量：x{{ item.num }}
                            </div>
                          </div>
                          <div style="display: flex;justify-content: space-between;">
                            <div>
                              <span style="font-size:1.2rem;color:#827070;margin-right:2rem;">库存：{{
                                item.InventoryQuantity }}份</span>
                              <span style="font-size:1.2rem;color:#827070;margin-right:2rem;">已售：{{ item.SoldQuantity
                                }}份</span>
                            </div>
                            <div style="font-size: 2.5rem;font-weight: bold;color: #EC5D31;">
                              ￥{{
                                (item.CostPrice * item.num).toFixed(2)
                              }}
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>

                <span class="warning_tip"
                  v-if="portfolioBenefits.length > 1 ? false : true">您当前选择的权益与组合规则不符，请按照组合规则选择，鼠标悬浮在<i
                    class="el-icon-warning-outline" style="color:black;"></i>上查看组合规则。</span>
              </div>
            </div>

            <div class="list-box" v-if="!isEdit">
              <div class="left">已购买权益:</div>
              <div class="right">
                <div class="add_content" @click="openChildDrawer('purchasedList', 2)">
                  <i class="el-icon-plus"></i>
                  <span>点击添加权益</span>
                </div>
              </div>
            </div>
          </div>
          <!-- 基础信息 -->
          <div class="content-box">
            <div class="title">基础信息</div>
            <div class="list-box">
              <div class="left">所属项目:</div>
              <div class="right" :class="form.ProjectID == '' ? 'right_boder' : ''">
                <el-select :disabled="isEdit" v-model="form.ProjectID" placeholder="请选择所属项目" filterable clearable>
                  <el-option v-for="item in sourceList" :key="item.ID" :label="item.Name" :value="item.ID"></el-option>
                </el-select>
              </div>
            </div>
            <div class="list-box">
              <div class="left">权益标题:</div>
              <div class="right">
                <el-input v-model="form.Name" placeholder="请输入权益标题" :disabled="isEdit"></el-input>
              </div>
            </div>

            <div class="list-box" v-if="initData.lableList.options.length > 0" style="margin-bottom: 0;">
              <div class="left">已选权益标签：</div>
              <div class="right">
                <div class="exhibition">
                  <div class="exhibition_content">
                    <div class="exhibition_content_list" v-for="item in initData.lableList.options" :key="item">
                      <div class="content_list_name">{{ item }}</div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="list-box" v-if="!isEdit">
              <div class="left">权益标签:</div>
              <div class="right">
                <div class="add_content" @click="ShowLabelDialog">
                  <i class="el-icon-plus"></i>
                  <span>点击添加标签</span>
                </div>
              </div>
            </div>

            <div class="list-box" v-if="initData.compnyList.options.length" style="margin-bottom: 0;">
              <div class="left">已选采购公司权限：</div>
              <div class="right">
                <div class="exhibition">
                  <div class="exhibition_content">
                    <div class="exhibition_content_list" v-for="item in initData.compnyList.options" :key="item">
                      <div class="content_list_name">{{ item }}</div>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <div class="list-box" v-if="!isEdit">
              <div class="left">采购公司权限设置:</div>
              <div class="right">
                <div class="add_content" @click="ShowCompngDialog">
                  <i class="el-icon-plus"></i>
                  <span>点击添加权限</span>
                </div>
              </div>
            </div>
            <div class="list-box">
              <div class="left">使用期限:</div>
              <div class="right">
                {{ getDataStartAndEnd.str }}
              </div>
            </div>
            <div class="list-box" v-if="portfolioBenefits.length">
              <div class="left">包含权益期限:</div>
              <div class="right">
                <div v-for="item in portfolioBenefits" :key="item.ID">
                  <div style="font-size: 1.8rem;font-weight: 700;">
                    {{ item.Name }}
                  </div>
                  <div style="margin-top: -1rem;">
                    {{ item.EffectiveTime }} 至
                    {{ item.ExpireTime }}
                  </div>
                </div>
              </div>
            </div>
            <div class="list-box">
              <div class="left">库存数量(份):</div>
              <div class="right">
                <el-input v-model="form.inventory" placeholder="请输入库存数量" :disabled="isEdit"></el-input>
                <!-- <el-input-number v-model="form.inventory" :max="calculate" :min="1" placeholder="请输入库存数量"
                                    :controls="false"></el-input-number> -->
                <div class="warning_tip" v-if="form.inventory > calculate.num">
                  库存数量不允许大于{{
                    calculate.obj ? calculate.obj.Name : ""
                  }}的{{
                    calculate.obj ? calculate.obj.InventoryQuantity : 0
                  }}个
                </div>
                <div class="warning_tip" v-if="calculate.obj && form.inventory < 1">
                  库存数量不允许小于单个权益最低库存数
                </div>
              </div>
            </div>
            <div class="list-box" v-if="portfolioBenefits.length">
              <div class="left"></div>
              <div class="right">
                <div style="font-size: 1.8rem;font-weight: 700;">
                  所选权益库存数量：
                </div>
                <div v-for="item in portfolioBenefits" :key="item.ID">
                  {{ item.Name }}：{{ item.InventoryQuantity }} 份
                </div>
              </div>
            </div>

            <div class="list-box">
              <div class="left">起购数量(份):</div>
              <div class="right">
                <el-input v-model="form.MPnum" placeholder="请输入起购数量" :disabled="isEdit"></el-input>
                <!-- <el-input-number v-model="form.MPnum" :max="calculate" :min="1" placeholder="请输入起购数量"
                                    :controls="false"></el-input-number> -->
                <div class="warning_tip" v-if="calculate.obj && form.MPnum < 1">
                  起购数量不允许小于0个
                </div>
                <div class="warning_tip" v-if="
                  calculate.obj &&
                  form.MPnum > calculate.obj.InventoryQuantity
                ">
                  起购数量不允许大于{{ calculate.obj.Name }}的{{
                    calculate.obj.InventoryQuantity
                  }}个
                </div>
                <div class="warning_tip" v-if="form.MPnum > form.inventory">
                  起购数量不允许大于设置的库存数量！
                </div>
              </div>
            </div>
            <div class="list-box" v-if="portfolioBenefits.length">
              <div class="left"></div>
              <div class="right">
                <div style="font-size: 1.8rem;font-weight: 700;">
                  所选权益起购数量：
                </div>
                <div v-for="item in portfolioBenefits" :key="item.ID">
                  {{ item.Name }}：{{ item.MinimumQuantity }} 份
                </div>
              </div>
            </div>
            <div class="list-box">
              <div class="left">市场价格(元):</div>
              <div class="right">
                <span>
                  {{
                    portfolioBenefits.length == 0
                      ? "--"
                      : '¥' + getNum(getDataStartAndEnd.SalePrice)
                  }}</span>
              </div>
            </div>
            <div class="list-box">
              <div class="left">平台价格(元):</div>
              <div class="right">
                {{
                  portfolioBenefits.length == 0
                    ? "--"
                    : '¥' + getNum(getDataStartAndEnd.CostPrice)
                }}
              </div>
            </div>
            <div class="list-box">
              <div class="left">服务费:</div>
              <div class="right right_table">
                <div class="tab-row">
                  <div style="width: 50%;">权益名称</div>
                  <div style="width: 25%;text-align: center;">
                    权益平台服务费
                  </div>
                  <div style="width: 25%;text-align: center;">小程序服务费</div>
                </div>
                <div class="tab-row" v-for="item in portfolioBenefits" :key="item.ID">
                  <div style="width: 50%;">{{ item.Name }}</div>
                  <div style="width: 20%;text-align: center;">
                    {{ item.PlatformServiceRate * 100 }}%
                  </div>
                  <div style="width: 20%;text-align: center;">
                    {{ item.EquityServiceRate * 100 }}%
                  </div>
                </div>
              </div>
            </div>

            <div class="list-box">
              <div class="left">让利积分:</div>
              <div class="right">
                <div>{{ form.Integral }}分</div>
                <div v-for="item in portfolioBenefits" :key="item.ID">
                  {{ item.Name }}：{{ item.Integral }} 分
                </div>
              </div>
            </div>

            <div class="list-box">
              <div class="left">平台结算价格(元)</div>
              <div class="right">
                <div>{{ form.platformSettlement == '--'? '--' : '¥'+form.platformSettlement }}</div>
                <div v-for="item in portfolioBenefits" :key="item.ID">
                  <block v-if="
                    item.CompanyID == octopus.passport.authorization.company
                  ">
                    {{ item.Name }}：{{
                      getNum(
                        (item.CostPrice -
                          item.CostPrice * item.PlatformServiceRate) *
                        item.num
                      )
                    }}
                  </block>
                  <block v-else>
                    {{ item.Name }}：{{ item.CostPrice * item.num }}
                  </block>
                  元
                </div>
              </div>
            </div>

            <div class="list-box">
              <div class="left">小程序结算价格(元)</div>
              <div class="right">
                <div>{{ form.APPSettlement == '--' ? '--' : '¥'+form.APPSettlement}}</div>
                <div v-for="item in portfolioBenefits" :key="item.ID">
                  <block v-if="
                    item.CompanyID == octopus.passport.authorization.company
                  ">
                    {{ item.Name }}：{{
                      getNum(
                        (item.CostPrice -
                          item.CostPrice *
                          (item.EquityServiceRate +
                            item.PlatformServiceRate) -
                          item.Integral / 10) *
                        item.num
                      )
                    }}
                  </block>
                  <block v-else>
                    {{ item.Name }}：{{ item.CostPrice * item.num }}
                  </block>
                  元
                </div>
              </div>
            </div>

            <div class="list-box alitem">
              <div class="left">是否允许在其他国企民企平台进行售卖</div>
              <div class="right">
                <el-radio v-model="form.channel" :label="1" :disabled="isEdit">是</el-radio>
                <el-radio v-model="form.channel" :label="0" :disabled="isEdit">否</el-radio>
              </div>
            </div>

            <div class="list-box">
              <div class="left">使用人数:</div>
              <div class="right right_table">
                <div class="flexRow">
                  <div style="width: 70%;">权益名称</div>
                  <div style="width: 30%;text-align: center;">使用人数</div>
                </div>
                <div class="flexRow" v-for="item in portfolioBenefits" :key="item.ID">
                  <div style="width: 70%;">{{ item.Name }}</div>
                  <div style="width: 30%;text-align: center;">
                    {{ item.UsersCount }}人
                  </div>
                </div>
              </div>
            </div>
            <div class="list-box">
              <div class="left">是否允许退款</div>
              <div class="right">
                <el-radio-group v-model="form.radio" @input="changeRadio" :disabled="isEdit">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="0">否</el-radio>
                  <!-- <el-radio label="2">允许部分退款</el-radio> -->
                </el-radio-group>
              </div>
            </div>
            <div class="list-box" v-if="form.radio == 2">
              <div class="left">可退款权益</div>
              <div class="right">
                <div class="add_content" @click="openRefund()">
                  <i class="el-icon-plus"></i>
                  <span>点击添加权益</span>
                </div>
              </div>
            </div>
            <!-- 主图 -->
            <div class="list-box">
              <div class="left">权益主图：</div>
              <div class="right">
                主图仅可上传1张图片，图片不超过512KB，仅支持jpg、png格式，建议比例1：1
              </div>
            </div>
            <div class="list-box">
              <div class="left"></div>
              <div class="right">
                <update ref="update1" :num="1" :octopus="octopus" :list="masterImg" @imgList="getMasterList"
                  :isEdit="isEdit"></update>
              </div>
            </div>
            <!-- 附图 -->
            <div class="list-box">
              <div class="left">权益附图：</div>
              <div class="right">
                附图可上传7张图片，单张图片不超过512KB，仅支持jpg、png格式，建议比例1：1
              </div>
            </div>
            <div class="list-box">
              <div class="left"></div>
              <div class="right">
                <update ref="update2" :num="7" :octopus="octopus" :multiple="true" :list="figuresList"
                  @imgList="getFiguresList" :isEdit="isEdit"></update>
              </div>
            </div>
          </div>

          <!-- 权益内容 -->
          <div class="content-box">
            <div class="title">权益内容</div>
            <div class="list_box" style="display: block;">
              <div class="left pd20-0">权益详情:</div>
              <div class="right" style="width: 100%;line-height: 1rem;">
                <quill ref="quill" :desc="form.deltedContent" :octopus="octopus" @quillContent="getQuillContent"
                  key="quill3" refName="quill3" refInput="quill3i" :isEdit="isEdit">
                </quill>
              </div>
            </div>
            <div class="list_box" style="display: block;">
              <div class="left pd20-0">使用规则:</div>
              <div class="right" style="width: 100%;line-height: 1rem;">
                <quill ref="quillRules" :desc="form.rulesContent" :octopus="octopus"
                  @quillContent="getQuillRulesContent" key="quill4" refName="quill4" refInput="quill4i"
                  :isEdit="isEdit">
                </quill>
              </div>
            </div>
          </div>
          <div class="list-box" v-if="form.radio != 0 && isRules">
            <div class="left">退款是否需要审核：</div>
            <div class="right">是</div>
          </div>
          <div class="list-box" v-if="form.radio != 0 && isRules">
            <div class="list-box">
              <div class="left">退款规则</div>
              <div class="right" v-if="form.radio == 1">
                <div v-for="item in portfolioBenefits" :key="item.ID">
                  {{ item.Name }}
                  <div class="rules">
                    <div v-for="jtem in item.rules" :key="jtem">
                      自权益使用至日期前{{
                        jtem.TypeID == 1
                          ? jtem.TimeLimit / 24 + "天"
                          : jtem.TimeLimit + "天"
                      }}支持退款{{ jtem.ServiceCharge }}%
                    </div>
                  </div>
                </div>
              </div>
              <div class="right" v-if="form.radio == 2">
                <div v-for="item in initData.rulesContent.options" :key="item.ID">
                  {{ item.Name }}
                  <div class="rules">
                    <div v-for="jtem in item.rules" :key="jtem">
                      自权益使用至日期前{{
                        jtem.TypeID == 1
                          ? jtem.TimeLimit / 24 + "天"
                          : jtem.TimeLimit + "天"
                      }}支持退款{{ jtem.ServiceCharge }}%
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <div class="button_list" v-if="type != 'look'">
            <button style="background-color: #1E1B19;" @click="addList(1)">
              存入草稿
            </button>
            <button @click="addList(2)">发布</button>
          </div>
        </div>
      </div>
    </el-drawer>
    <!-- 选择权益 -->
    <addOwnRights ref="OwnRight" @ownRightList="getOwnList"></addOwnRights>
    <!-- 选择标签 -->
    <LabelDialog ref="LabelDialog" @lableList="getLableList"></LabelDialog>
    <!-- 采购公司权限 -->
    <CompnyDialog ref="CompnyDialog" @compnyList="getCompnyList"></CompnyDialog>
    <!-- 退款规则 -->
    <addRefund ref="Refund" @addRefundList="addRefundList" :portfolioBenefits="portfolioBenefits"></addRefund>
  </div>
</template>

<script>
import update from "@/components/Components/imgUpdate.vue";
import quill from "@/components/Components/quillEditor.vue";
import addOwnRights from "./addOwnRights.vue";
import LabelDialog from "./labelDialog.vue";
import CompnyDialog from "./compnyDialog.vue";
import addRefund from "./addRefund.vue";
export default {
  name: "",
  components: {
    update,
    quill,
    addOwnRights,
    LabelDialog,
    CompnyDialog,
    addRefund
  },
  props: {
    isEdit: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    portfolioBenefits() {
      return [
        ...this.initData.ownList.options,
        ...this.initData.purchasedList.options
      ];
    },
    calculate() {
      let num = 0,
        obj = {};
      let arr1 = [],
        arr2 = [],
        arr = [
          ...this.initData.ownList.options,
          ...this.initData.purchasedList.options
        ];
      this.initData.ownList.options.map(v => {
        arr1.push(v.InventoryQuantity / v.num);
      });
      this.initData.purchasedList.options.map(v => {
        arr2.push(v.InventoryQuantity / v.num);
      });
      num = arr.length == 0 ? "" : Math.floor(Math.min(...[...arr1, ...arr2]));
      this.form.MPnum = arr.length == 0 ? "" : 1;
      obj = arr.find(
        x => Math.floor(x.InventoryQuantity / x.num) == num
      );

      return { num, obj };
    },
    getDataStartAndEnd() {
      let obj = {},
        dataTime = [],
        str = "",
        newArr = [],
        SalePrice = "--",
        CostPrice = "--",
        Integral = "--",
        platformSettlement = "--",
        APPSettlement = "--";
      let arr = [
        ...this.initData.ownList.options,
        ...this.initData.purchasedList.options
      ];
      if (arr.length > 0) {
        this.form.EquityListId = "";
        arr.map(v => {
          newArr.push(new Date(v.EffectiveTime));
          newArr.push(new Date(v.ExpireTime));
          SalePrice == "--"
            ? (SalePrice = 0 + v.SalePrice * v.num)
            : (SalePrice += v.SalePrice * v.num);
          console.log(SalePrice);

          CostPrice == "--"
            ? (CostPrice = 0 + v.CostPrice * v.num)
            : (CostPrice += v.CostPrice * v.num);
          Integral == "--"
            ? (Integral = 0 + v.Integral * v.num)
            : (Integral += v.Integral * v.num);
          this.form.EquityListId == ""
            ? (this.form.EquityListId = v.ID)
            : (this.form.EquityListId = this.form.EquityListId + "," + v.ID);
        });
        dataTime = [
          this.timestampToDate(Math.min(...newArr)),
          this.timestampToDate(Math.max(...newArr))
        ];
        str = `${dataTime[0]} 至 ${dataTime[1]}`;
      }
      if (arr.length == 0) {
        str = `-- 至 --`;
      }
      this.initData.ownList.options.map(v => {
        // 计算平台结算价格
        // 权益平台结算价格=所选自有权益的平台价格之和-（所选自有权益的平台价格之和*自有权益的权益平台服务费）+已购买权益平台价格之和
        platformSettlement == "--"
          ? (platformSettlement =
            (0 + v.CostPrice - v.CostPrice * v.PlatformServiceRate) *
            v.num)
          : (platformSettlement =
            platformSettlement +
            (v.CostPrice - v.CostPrice * v.PlatformServiceRate) *
            v.num);
        // 计算小程序结算价格
        //小程序结算价格=各自有权益结算价格之和+已购权益平台价之和,
        //各自有权益结算价格之和={单个自有权益平台价-[单个自有权益平台价*(其小程序服务费+其平台服务费)]-（让利积分/10）}
        APPSettlement == "--"
          ? (APPSettlement =
            (0 +
              v.CostPrice -
              v.CostPrice * (v.EquityServiceRate + v.PlatformServiceRate) -
              v.Integral / 10) *
            v.num)
          : (APPSettlement +=
            (v.CostPrice -
              v.CostPrice * (v.EquityServiceRate + v.PlatformServiceRate) -
              v.Integral / 10) *
            v.num);
      });
      this.initData.purchasedList.options.map(v => {
        // 计算小程序结算价格
        platformSettlement == "--"
          ? (platformSettlement = 0 + v.CostPrice)
          : (platformSettlement += v.CostPrice);
        APPSettlement == "--"
          ? (APPSettlement = 0 + v.CostPrice)
          : (APPSettlement += v.CostPrice);
      });
      obj.str = str; // 时间区间
      obj.EffectiveTime = dataTime[0];
      obj.ExpireTime = dataTime[1];
      obj.SalePrice = SalePrice; //市场价格
      obj.CostPrice = CostPrice; //平台价格
      this.form.Integral = Integral; //让利积分
      this.form.platformSettlement =
        platformSettlement > 0
          ? this.getNum(platformSettlement)
          : platformSettlement; //平台结算价格
      this.form.APPSettlement =
        APPSettlement > 0 ? this.getNum(APPSettlement) : APPSettlement; // 小程序结算价格
      return obj;
    }
  },
  data() {
    return {
      octopus: this.$parent.octopus,
      drawer: false,
      runles: {
        //字段规则，验证使用
        ProjectID: { required: true, message: "请选择所属项目" },
        EquityListId: {
          required: true,
          message: "组合权益选择不符合要求！",
          reg: /^(\d+,){1,}\d+$/
        },
        Name: { required: true, message: "请输入权益名称（标题）" },
        tableListId: { required: true, message: "请选择权益标签" },
        inventory: {
          required: true,
          message: "请输入正确的库存数量",
          reg: () => {
            return this.form.inventory < 1 ||
              this.form.inventory > this.calculate.num
              ? false
              : true;
          }
        },
        MPnum: {
          required: true,
          message: "请输入正确的起购数量",
          reg: () => {
            return this.form.MPnum < 1 ||
              this.form.MPnum > this.calculate.obj.InventoryQuantity
              ? false
              : true;
          }
        },
        masterImg: { required: true, message: "请上传一张权益主图" },
        figuresList: { required: true, message: "请上传至少一张权益附图！" },
        deltedContent: { required: true, message: "请输入权益详情" },
        rulesContent: { required: true, message: "请输入使用规则！" }
      },
      form: {
        //提交字段
        ProjectID: '',//所属项目
        id: "",
        Name: "", //权益名称（标题）
        EffectiveTime: "", //生效时间
        ExpireTime: "", //过期时间
        inventory: 1, //库存数量
        MPnum: "", //起购数量
        SalePrice: "", //市场价格
        platformPrice: "", //权益平台服务费
        Integral: 0, //让利积分
        platformSettlement: 0, //平台结算价格
        APPSettlement: 0, //小程序结算平台
        channel: 1, //是否允许在其他国企民企平台进行售卖
        radio: 0, //是否退款
        masterImg: [], //主图
        figuresList: [], //附图
        oldInventory: "", //旧库存 ，用于比较修改库存时使用
        minInventory: 0, //最小库存
        maxInventory: 0, //最大库存
        MinimumQuantity: 0, //最小起购数
        maximumQuantity: 0, //最大起购数
        tableListId: "", //标签 ID
        deltedContent: "", //权益详情
        rulesContent: "", //权限规则
        EquityListId: "", //权益包ID
        compnyListID: "" //采购公司限制
      },
      initData: {
        //初始化数据
        ownList: {
          //选择的自有权益
          value: [], //选中值
          options: [] //列表
        },
        purchasedList: {
          //选择的已购买权益
          value: [], //选中值
          options: [] //列表
        },
        lableList: {
          //选择的权益标签
          value: [], //选中值
          options: [] //列表
        },
        compnyList: {
          //已选采购公司权限
          value: [], //选中值
          options: [] //列表
        },
        deltedContent: {
          //权益详情
          value: "",
          options: []
        },
        rulesContent: {
          //规则
          value: "",
          options: []
        }
      },
      isRules: false,
      type: "CREATE", // 判断是否是新建，还是编辑
      figuresList: [],
      masterImg: [],
      isCanChangeList: [],//不变的数据
      sourceList: []
    };
  },
  watch: {},
  created() {
    this.api_1415();
  },
  methods: {
    drawerOp(data, type, flag = false) {
      if (!flag) {
        this.drawer = true;
        Object.entries(this.form).map(([v, value]) => {
          if (typeof (value) == 'number') { this.form[v] = 0; }
          if (typeof (value) == 'string') { this.form[v] = ''; }
          if (typeof (value) == 'object') { this.form[v] = []; }
        })
        this.initData.ownList.options = [];
        this.initData.purchasedList.options = [];
        this.initData.lableList.options = [];
        this.initData.compnyList.options = [];
        this.masterImg = [];
        this.figuresList = [];

        return;
      }
      this.api_1308(data.row.ID);

      this.type = type; //父级传过来 是编辑还是新建
      this.form.Name = data.row.Name;
      this.form.ProjectID = data.row.ProjectID;
      this.initData.lableList.options = data.row.EquityFlagListName
        ? data.row.EquityFlagListName.split(",")
        : "";
      this.initData.lableList.value = this.form.tableListId =
        data.row.EquityFlagList;
      this.initData.compnyList.options = data.row.TransferRuleIDName
        ? data.row.TransferRuleIDName.split(",")
        : "";
      this.initData.compnyList.value = this.form.compnyListID = data.row
        .TransferRuleID
        ? data.row.TransferRuleID.split(",")
        : "";
      this.form.Integral = data.row.Integral;
      this.form.inventory = data.row.InventoryQuantity;
      this.form.platformSettlement = data.row.CostPrice;
      this.form.APPSettlement = data.row.EquityServiceRate;
      this.form.channel = Number(data.row.IsOpenSale);
      this.form.radio = Number(data.row.IsRefund);

      this.form.deltedContent = data.row.Description;
      this.form.rulesContent = data.row.UseRuleDescription;

      this.form.masterImg = this.masterImg = data.row.MainPicturePath
        ? JSON.parse(data.row.MainPicturePath)
        : [];

      this.form.figuresList = this.figuresList = data.row.SecondaryPicturePath
        ? JSON.parse(data.row.SecondaryPicturePath)
        : [];

      this.form.id = data.row.ID;
      this.$forceUpdate();

      this.$nextTick(() => {
        this.drawer = true;
      });
    },
    openChildDrawer(type = "ownList") {
      this.$refs.OwnRight.drawerOp(
        type,
        type == "ownList" ? 1181 : 1182,
        type == "ownList"
          ? this.initData.ownList.options
          : this.initData.purchasedList.options,
        this.type
      );
    },
    ShowLabelDialog() {
      this.$refs.LabelDialog.drawerOp(this.initData.lableList.value);
    },
    ShowCompngDialog() {
      this.$refs.CompnyDialog.drawerOp(this.initData.compnyList.value);
    },
    openRefund() {
      this.$refs.Refund.drawerOp();
    },
    //获取选择的自有权益列表,获取选择的已购权益列表 与该权益的最大库存
    getOwnList(list, max, type, min) {

      this.initData[type].value = max;
      this.initData[type].MPnum = min;
      this.initData[type].options = list;
    },
    getLableList(list, listID) {
      this.initData.lableList.options = list;
      this.initData.lableList.value = this.form.tableListId = listID.join(",");
    },
    getCompnyList(list, typeArr, scaleArr, fundArr, industryArr) {
      this.initData.compnyList.options = list;
      this.form.compnyListID = [
        ...typeArr,
        ...scaleArr,
        ...fundArr,
        ...industryArr
      ];
    },
    // 删除自有权益
    removeOwnlist(id, i) {
      this.initData.ownList.options.splice(i, 1);
      // Math.floor(Math.min(...[this.initData.ownList.value, this.initData.purchasedList.value]))
      this.$refs.OwnRight.changeTableStatus(id);
    },
    // 删除已购权益
    removePurchasedList(id, i) {
      this.initData.purchasedList.options.splice(i, 1);
      this.$refs.OwnRight.changeTableStatus(id);
    },
    // 权益详情
    getQuillContent(list) {
      this.form.deltedContent = list;
    },
    getQuillRulesContent(list) {
      this.form.rulesContent = list;
    },
    addRefundList(e) {
      let str = this.getStr(e, "ID");
      this.getRules(str, 2);
    },
    changeRadio(e) {
      this.rules = false;
      if (e == 1) {
        let id = this.type == "CREATE" ? "ID" : "MainEquityID";
        let str = this.getStr(this.portfolioBenefits, id);
        if (str == "") {
          this.$message({
            message: "请先选择权益后重新选择是否退款。",
            type: "warning"
          });
          return;
        }
        this.getRules(str, 1);
      }
      if (e == 2) {
        this.initData.rulesContent.options = [];
      }
    },
    // 退款规则
    getRules(id, type) {
      this.isRules = false;
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1241,
          cellData: [
            { name: "CompanyID" }, // 公司ID
            { name: "CreateTime" }, // 创建时间
            { name: "CreateUserID" }, // 创建人
            { name: "EquityID" }, // 权益ID
            { name: "EquityName" }, // 权益名称
            { name: "ID" }, // ID
            { name: "InventoryID" }, // 库存
            { name: "Name" }, // 规则名称
            { name: "ProductID" }, // 产品
            { name: "ServiceCharge" }, // 手续费（%）
            { name: "Status" }, // 是否启用
            { name: "TimeLimit" }, // 时限（默认小时）
            { name: "TypeID" }, // 规则类型（1小时  2天）
            { name: "UpdateTime" } // 修改时间
          ],
          paramData: {
            EquityID: id
          }
        },
        data => {
          if (data.status.code == 200) {
            this.radioEle(type, data.content.queryData);
          } else {
            this.octopus.tips.error(data);
          }
        }
      );
    },
    api_1308(id) {
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1308,
          cellData: [
            { name: "CompanyID" },	// CompanyID
            { name: "CompanyIDName" },	// CompanyIDName
            { name: "ProjectID" },	// ProjectID
            { name: "CostPrice" }, // 单价
            { name: "EffectiveTime" }, // 生效时间
            { name: "EquityCount" }, // 权益数量
            { name: "EquityID" }, // EquityID
            { name: "ExpireTime" }, // 到期时间
            { name: "ID" }, // ID
            { name: "InventoryQuantity" }, // 库存
            { name: "IsOwn" }, // 是否自有
            { name: "MainInventoryID" }, // 主库存ID
            { name: "MainPicturePath" }, // 主图
            { name: "Name" }, // 权益名称
            { name: "SoldQuantity" }, // 已售数量
            { name: "EquityFlagListName" }, // 标签名称
            { name: "MinimumQuantity" }, // 起购数量
            { name: "SalePrice" }, // 市场价格
            { name: "PlatformServiceRate" }, // PlatformServiceRate
            { name: "EquityServiceRate" }, // EquityServiceRate
            { name: "Integral" }, // Integral
            { name: "UsersCount" }, // UsersCount
            { name: "MainEquityID" } // UsersCount
          ],
          paramData: {
            EquityID: id
          }
        },
        data => {
          if (data.status.code == 200) {
            this.initData.ownList.options = data.content.queryData.filter(
              x => x.Isown == 1
            );
            this.initData.ownList.options.map(v => { v.num = v.EquityCount })
            this.initData.purchasedList.options = data.content.queryData.filter(
              x => x.Isown == 0
            );
            this.initData.purchasedList.options.map(v => { v.num = v.EquityCount })
            this.isCanChangeList = JSON.parse(
              JSON.stringify([
                ...this.initData.ownList.options,
                ...this.initData.purchasedList.options
              ])
            );
            if (this.form.radio == 1) {
              this.changeRadio(1);
            }
            // this.$forceUpdate()
          } else {
            this.octopus.tips.error(data);
          }
        }
      );
    },
    getStr(arr, code) {
      let str = "";
      arr.map(v => {
        str == "" ? (str += v[code]) : (str += "," + v[code]);
      });
      return str;
    },
    radioEle(type, list) {
      if (this.type != "CREATE") {
        this.portfolioBenefits.map((v, i) => {
          v.rules = [];
          list.map(x => {
            if (x.EquityID == v.MainEquityID) {
              v.rules.push(x);
            }
          });
        });
      } else {
        this.portfolioBenefits.map((v, i) => {
          v.rules = [];
          list.map(x => {
            if (x.EquityID == v.ID) {
              v.rules.push(x);
            }
          });
        });
        this.initData.rulesContent.options = this.portfolioBenefits.filter(
          x => x.rules.length > 0
        );
      }
      this.$nextTick(() => {
        this.isRules = true;
      });
    },
    getMasterList(list) {
      this.form.masterImg = list;
    },
    getFiguresList(list) {
      this.form.figuresList = list;
    },

    getTag(str) {
      let arr = str.split(",");
      return arr;
    },
    timestampToDate(timestamp) {
      const date = new Date(timestamp);
      const year = date.getFullYear();
      const month = ("0" + (date.getMonth() + 1)).slice(-2);
      const day = ("0" + date.getDate()).slice(-2);
      const hours = ("0" + date.getHours()).slice(-2);
      const minutes = ("0" + date.getMinutes()).slice(-2);
      const seconds = ("0" + date.getSeconds()).slice(-2);
      return (
        year +
        "-" +
        month +
        "-" +
        day +
        " " +
        hours +
        ":" +
        minutes +
        ":" +
        seconds
      );
    },
    async addList(type = 2) {

      if (this.initData.ownList.options.length == 0) {
        this.octopus.tips.error('请至少选择一个自由权益。');
        return
      }

      if (!this.octopus.tools.verify(this.form, this.runles)) {
        return;
      }
      let cellData_748 = [
        {
          name: "CompanyID",
          defaultValue: this.octopus.passport.authorization.company
        }, // 公司ID
        // { name: "CostPrice", defaultValue: this.getDataStartAndEnd.CostPrice }, // 市场价格
        { name: "ProjectID", defaultValue: this.form.ProjectID },	// 项目ID
        {
          name: "CreateTime",
          defaultValue:
            new Date().toJSON().substring(0, 10) +
            " " +
            new Date().toTimeString().substring(0, 8)
        }, // 创建时间
        { name: "CreateUserID", defaultValue: this.octopus.passport.id }, // 创建人
        { name: "Description", defaultValue: this.form.deltedContent }, // 权益内容
        {
          name: "EffectiveTime",
          defaultValue: this.getDataStartAndEnd.EffectiveTime
        }, // 生效日期
        { name: "EquityList", defaultValue: this.form.EquityListId }, // 外部权益包列表  字符串(逗号分开)
        {
          name: "ExpireTime",
          defaultValue: this.getDataStartAndEnd.ExpireTime
        }, // 过期时间
        { name: "FlagList", defaultValue: this.form.tableListId }, // 权益标签
        { name: "ID" }, // ID
        { name: "Integral", defaultValue: this.form.Integral }, // 让利积分
        { name: "IsOpenSale", defaultValue: this.form.channel }, // 是否允许在其他国企平台售卖(1.允许,0.不允许)
        { name: "IsRefund", defaultValue: this.form.radio }, // 是否允许退款
        {
          name: "MainPicturePath",
          defaultValue: JSON.stringify(this.form.masterImg)
        }, // 主图
        { name: "MinimumQuantity", defaultValue: this.form.MPnum }, // 起售数量
        { name: "Name", defaultValue: this.form.Name }, // 权益名称（标题）
        // { name: "ProductID", defaultValue: this.productsSelect.value },	// ProductID
        // { name: "SalePrice", defaultValue: this.getDataStartAndEnd.SalePrice }, // 发售价（平台价格）
        {
          name: "SecondaryPicturePath",
          defaultValue: JSON.stringify(this.form.figuresList)
        }, // 副图
        {
          name: "Status",
          defaultValue:
            type == 1
              ? 1
              : this.octopus.passport.authorization.company == 1
                ? 5
                : 2
        }, // 权益状态（保存未提交（草稿箱）、已提交/待审核、审核通过、审核未通过、未启用，启用、已售完、到期）
        {
          name: "TransferRuleID",
          defaultValue:
            this.form.compnyListID == "" ? "" : this.form.compnyListID.join()
        }, // 采购公司限制
        // { name: "TypeID" , defaultValue: this.typeSelect.value},	// 权益类型(单个类型、多个类型)
        { name: "TypeID", defaultValue: 2 }, // 权益类型(单个类型、多个类型)
        {
          name: "UpdateTime",
          defaultValue:
            new Date().toJSON().substring(0, 10) +
            " " +
            new Date().toTimeString().substring(0, 8)
        }, // 修改时间
        { name: "UseRuleDescription", defaultValue: this.form.rulesContent }, // 权益使用规则
        { name: "IsConfirm", defaultValue: this.auditRadio }, //  商家二次确认
        { name: "EquityCount", defaultValue: this.form.inventory } // EquityCount
        // { name: 'usersCount' , defaultValue:this.inputValue.usersCount},//人数
      ];

      let txt =
        type == 1
          ? "确定存入草稿库吗?"
          : "请仔细确认提交数据，该操作不可逆，确定创建该组合权益吗?";
      this.$confirm(txt, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.api_748(cellData_748, type);
        })
        .catch(() => {
          console.log("取消了");
        });
    },
    api_748(cellData, type = 2) {
      this.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 748,
          type: this.type,
          value: this.type == "CREATE" ? "" : this.form.id,
          cellData: cellData
        },
        res => {
          if (res.status.code == 200) {
            let arr = [],
              last = null;
            let arrC = this.compareArrays(
              this.isCanChangeList,
              this.portfolioBenefits
            );
            arrC.map((v, i) => {
              last = i == arrC.length - 1 ? true : false;
              this.api_1322(res, type, v, last);
            });
          } else {
            this.octopus.tips.error(res);
          }
        }
      );
    },
    api_CreateEquityRecord(res) {
      this.octopus.tools.openAPI(
        "/ESB/AIGC/CreateEquityRecord",
        {
          companyID: this.octopus.passport.project, // 权益所属公司ID
          equityID: res.content.value, // 权益ID
          quantity: this.form.inventory, // 组合权益数量
          createUserID: this.octopus.passport.id, // 创建人
          channelID: 1 //直接通过
        },
        datas => {
          if (datas.content.status == 200) {
            this.api_cmbEquity(res);
          } else {
            this.octopus.tips.error(datas);
          }
        }
      );
    },
    api_1186(data) {
      this.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 1186,
          type: this.type,
          value: this.type == "CREATE" ? "" : this.form.id,
          cellData: [
            {
              name: "CompanyID",
              defaultValue: this.octopus.passport.authorization.company
            }, // 公司ID
            {
              name: "CreateTime",
              defaultValue:
                new Date().toJSON().substring(0, 10) +
                " " +
                new Date().toTimeString().substring(0, 8)
            }, // 创建时间
            { name: "CreateUserID", defaultValue: this.octopus.passport.id }, // 创建人
            { name: "EquityCount", defaultValue: this.form.inventory }, // 库存数量
            { name: "EquityID", defaultValue: data.content.value }, // 权益ID
            { name: "ID" }, // ID
            {
              name: "UpdateTime",
              defaultValue:
                new Date().toJSON().substring(0, 10) +
                " " +
                new Date().toTimeString().substring(0, 8)
            }, // 修改时间
            { name: "TypeID", defaultValue: 2 } // TypeID
          ]
        },
        res => {
          if (res.status.code == 200) {
            this.api_1196(data);
          } else {
            this.octopus.tips.error(res);
          }
        }
      );
    },
    api_1196(data, status = true) {
      this.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 1196,
          type: "CREATE",
          // value: this.type == "CREATE" ? "" : this.form.id,
          cellData: [
            {
              name: "CreateTime",
              defaultValue:
                new Date().toJSON().substring(0, 10) +
                " " +
                new Date().toTimeString().substring(0, 8)
            }, // 时间
            { name: "CreateUserID", defaultValue: this.octopus.passport.id }, // 创建人
            { name: "EquityID", defaultValue: data.content.value }, // 权益ID
            { name: "ID" }, // ID
            { name: "Opinions", defaultValue: "新建组合权益" }, // 审核内容
            { name: "Status", defaultValue: 1 } // 审核状态
          ]
        },
        res => {
          if (res.status.code == 200) {
            this.$message({
              message: "创建成功,请等待审核。",
              type: "success"
            });
            this.createAuditStatus(res);
            // 获取用户组
            this.$utils.getGroupInfo(this, '超级管理员,高级管理员,业务管理员', 1).then((res) => {
              console.log('发送消息的用户组：', res);
              // 发送消息 传值说明 模版ID ，消息类型 ，消息里的字段 ，创建用户ID，接收公司ID，接收群组ID
              res.length > 0 && this.$utils.sendMessageMulti(5, 6, { CompanyName: this.initData.ownList.options[0].CompanyIDName, EquityName: this.form.Name }, this.octopus.passport.id, 1, res, this)
            });
            this.drawer = false;
            this.$emit("createdSuccess", 0);
          } else {
            this.octopus.tips.error(res);
          }
        }
      );
    },
    // 插入权益详情
    api_1322(data, type, res, last = null) {
      let o = this;

      let cellData = [];
      if (res.type == "CREATE") {
        cellData = [
          {
            name: "CreateTime",
            defaultValue:
              new Date().toJSON().substring(0, 10) +
              " " +
              new Date().toTimeString().substring(0, 8)
          }, // CreateTime
          { name: "CreateUserID", defaultValue: o.octopus.passport.id }, // CreateUserID
          { name: "EquityID", defaultValue: data.content.value }, // EquityID
          { name: "ID" }, // ID
          { name: "MainEquityID", defaultValue: res.ID }, // MainEquityID
          { name: "ProductID", defaultValue: res.ProductID }, // ProductID
          { name: "EquityCount", defaultValue: res.num }, // EquityCount
          { name: "CostPrice", defaultValue: res.CostPrice }, // CostPrice
          { name: "SalePrice", defaultValue: res.SalePrice } // SalePrice
        ];
      } else {
        cellData = [
          { name: "EquityCount", defaultValue: res.num } // EquityCount
        ];
      }

      return new Promise((resolve, reject) => {
        o.octopus.request.api.post(
          "/Octopus/Engine/Item",
          {
            id: 1322,
            type: res.type,
            value: res.type == "CREATE" ? "" : res.ID,
            cellData: cellData,
            paramData: {}
          },
          res => {
            if (res.status.code == 200) {
              if (last) {
                if (type == 1) {
                  this.drawer = false;
                  this.$emit("createdSuccess", 0);
                  this.$message({
                    message: "操作成功。",
                    type: "success"
                  });
                  return;
                }
                this.octopus.passport.authorization.company == 1
                  ? this.api_cmbEquity(data) //this.api_CreateEquityRecord(data)
                  : this.api_1186(data);
              }
              resolve(type);
            } else {
              o.octopus.tips.error(res);
              reject(res);
            }
          }
        );
      });
    },
    // 组合权益插入库存
    api_cmbEquity(res) {
      let list = [];
      let ID = this.type == "CREATE" ? "ID" : "MainEquityID";
      this.initData.ownList.options.map(v => {
        list.push({ equityID: v[ID], quantity: v.num });
      });
      this.initData.purchasedList.options.map(v => {
        list.push({ equityID: v[ID], quantity: v.num });
      });
      this.octopus.tools.openAPI(
        "/ESB/AIGC/cmbEquity",
        {
          userId: this.octopus.passport.id,
          equityId: res.content.value, //组合权益ID
          typeId: 2, //
          companyId: this.octopus.passport.authorization.company, // 公司ID
          quantity: this.form.inventory, //组合权益数量
          baseEquityList: list, // 组合权益的子权益
          channelId: "1" // 页面不同 创建页面传1 ，权益审核传2，库存管理传3
        },
        datas => {
          if (datas.content.status.code == 200) {
            this.createAuditStatus(res);
          } else {
            this.octopus.tips.error(datas);
            // 失败放到草稿库中
            this.is_turn_back(res.content.value);
          }
        }
      );
    },
    compareArrays(A, B) {
      let C = []; // 对比 B 数组中的每个对象

      B.forEach(objB => {
        // 在 A 数组中查找是否存在相同 id 的对象
        let foundInA = A.find(objA => objA.ID === objB.ID);

        if (!foundInA) {
          // 如果在 A 中找不到对应 id 的对象，则为 CREATE
          C.push({ ...objB, type: "CREATE" });
        } else {
          // 如果在 A 中找到了对应 id 的对象，则为 UPDATE
          C.push({ ...objB, type: "UPDATE" });
        }
      }); // 查找在 A 中存在但在 B 中不存在的对象，标记为 DELETE

      A.forEach(objA => {
        let foundInB = B.find(objB => objB.ID === objA.ID);
        if (!foundInB) {
          C.push({ ...objA, type: "DELETE" });
        }
      });

      return C;
    },
    // 添加审核历史
    createAuditStatus(data) {
      let status = null,
        o = this; // 1未提交  2审核中   4审核未通过   5未启用(审核通过)   6小程序启用     7平台启用
      o.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 1196,
          type: "CREATE",
          cellData: [
            { name: "EquityID", defaultValue: data.content.value }, //权益ID
            {
              name: "CreateTime",
              defaultValue:
                new Date().toJSON().substring(0, 10) +
                " " +
                new Date().toTimeString().substring(0, 8)
            }, // 时间
            {
              name: "Opinions",
              defaultValue: "审核通过"
            }, // 审核内容
            { name: "Status", defaultValue: 1 }, // 审核状态
            { name: "CreateUserID", defaultValue: o.octopus.passport.id } //创建人
          ]
        },
        data => {
          if (data.status.code == 200) {
            o.$emit("refresh");
            o.drawer = false;
            if (o.octopus.passport.authorization.company == 1) {
              this.$message({
                message: "创建成功 ",
                type: "success"
              });
            }

          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    is_turn_back(ID) {
      this.octopus.request.api.post(
        "/Octopus/Engine/Item",
        {
          id: 748,
          type: "UPDATE",
          value: ID,
          cellData: [
            { name: "Status", defaultValue: 3 } // 权益状态（保存未提交（草稿箱）、已提交/待审核、审核通过、审核未通过、未启用，启用、已售完、到期）
          ]
        },
        data => {
          if (data.status.code == 200) {
            this.$emit("refresh");
          } else {
            o.octopus.tips.error(data);
          }
        }
      );
    },
    //
    getPriceNum(num) {
      let n = Math.floor(num * 100) / 100;
      return n;
    },
    getNum(num) {
      let index = String(num).indexOf(".");
      if (index < 0) {
        index = 0
      }
      return String(num).substring(0, index + 3);
    },
    api_1415() {
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1415,
          cellData: [
            { name: "ID" },	// ID
            { name: "Name" },	// Name
          ],
          paramData: {}
        },
        data => {
          if (data.status.code == 200) {
            this.sourceList = data.content.queryData;
          } else {
            this.octopus.tips.error(data);
          }
        }
      );
    },
  }
};
</script>

<style scoped>
.list {
  position: relative;
  width: 100%;
  padding-top: 30%;
  margin-bottom: 1rem;
}

.list1 {
  position: relative;
  width: 10%;
  padding-top: 30%;
  margin-bottom: 1rem;
}

.item {
  position: absolute;
  display: flex;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.item1 {
  position: absolute;
  display: flex;
  align-items: center;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.drawer_box {
  padding: 2rem;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.drawer_t {
  display: flex;
  justify-content: space-between;
  position: absolute;
  width: 100%;
  padding: 2rem;
  top: 0;
  left: 0;
  background-color: #ffff;
  /* border-bottom: 1px solid #0000; */
}

.drawer_t_l {
  display: flex;
  align-items: center;
  font-size: 1.8rem;
  font-weight: bold;
}

.drawer_t_l_img {
  width: 2.8rem;
  margin-right: 1rem;
  vertical-align: middle;
}

.drawer_t_r {
  width: 3rem;
  height: 3rem;
  cursor: pointer;
  position: absolute;
  right: 6rem;
}

.block {
  width: 100%;
  height: 90vh;
  padding: 20px 0;
  margin-top: 20px;
  overflow-y: auto;
}

.content-box {
  box-shadow: inset 0px 0px 4px 0px #e9e9e9;
  background: #fdfdfd;
  border-radius: 1rem;
  padding: 2rem;
  margin-bottom: 2rem;
}

.title {
  font-weight: 700;
  font-size: 1.7rem;
}

/* 权益组合 */
.list-box {
  display: flex;
  width: 100%;
  justify-content: space-between;
}

.list-box {
  /* height: 3.5rem; */
  line-height: 4rem;
  margin-top: 2rem;
}

.list-box .left {
  width: 20%;
  font-size: 1.5rem;
  /* display: flex;
    align-items: center; */
}

.list-box .right {
  width: 80%;
}

.list-box .right .delte {
  font-size: 1.6rem;
  color: #898582;
  margin-left: 2rem;
  cursor: pointer;
}

.list-box .right .delte:hover {
  color: #f87338;
}

.list-box .right .add_content {
  height: 4.5rem;
  line-height: 4.5rem;
  border: 1px dashed #f87338;
  display: inline-block;
  padding: 0 1.5rem;
  cursor: pointer;
  border-radius: 0.5rem;
}

.list-box .right .el-input {
  width: 100%;
  height: 4.5rem;
}

.list-box .right .add_content i {
  color: #f87338;
  font-weight: 700;
  margin-right: 0.5rem;
}

.el-input__inner {
  cursor: pointer;
  padding-right: 35px;
  height: 100%;
}

.list-box .right>>>.el-input__inner {
  border: 1px solid #ff0000 !important;
}

.list-box .right .big-txt {
  font-size: 1.8rem;
  font-weight: 700;
}

.warning_tip {
  color: rgba(255, 0, 0, 0.996);
  font-size: 1.5rem;
  font-weight: 400;
}

.tab-row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  font-size: 1.8rem;
}

.flexRow {
  display: flex;
  justify-content: space-between;
  font-size: 1.8rem;
}

.alitem {
  align-items: center;
}

.pd20-0 {
  padding: 20px 0;
}

>>>.el-input__inner {
  cursor: pointer;
  padding-right: 35px;
  height: 100%;
}

>>>.el-input__icon {
  line-height: 3.5rem;
}

>>>.el-input__inner:focus {
  border-color: #f87338;
  outline: 0;
}

>>>.el-select {
  width: 100%;
  height: 4.5rem;
}

>>>.list-box .right .el-input {
  width: 100%;
  height: 4.5rem;
}

>>>.el-select .el-input.is-focus .el-input__inner {
  border-color: #f87338;
}

.el-select-dropdown__item.selected {
  color: #f87338 !important;
  font-weight: 700;
}

>>>.el-radio__input.is-checked+.el-radio__label {
  color: #f87338;
}

>>>.el-radio__input.is-checked .el-radio__inner {
  border-color: #f87338;
  background: #f87338;
}

.button_list {
  margin-top: 1rem;
  display: flex;
  justify-content: end;
  position: absolute;
  background-color: #ffff;
  bottom: 1rem;
  width: calc(100% - 7rem);
}

.button_list button {
  border: none;
  height: 4rem;
  width: 12rem;
  border-radius: 1rem;
  margin-left: 1rem;
  color: #ffff;
  background-color: #f78c53;
  cursor: pointer;
}

.exhibition {
  display: flex;
  justify-content: space-between;
  /* margin: 2rem 0; */
}

.exhibition_title {
  font-size: 1.6rem;
}

.exhibition_content {
  display: flex;
  flex-wrap: wrap;
  max-height: 10rem;
  height: 10rem;
  overflow: auto;
  background-color: #fff;
  border: 1px solid #dcdfe6;
  width: 100%;
  border-radius: 1rem;
  padding: 0.2rem;
  overflow: auto;
}

.exhibition_content div {
  display: flex;
  align-items: center;
  background-color: #fbf8f9;
  height: 3rem;
  padding: 0 0.4rem;
  margin: 0.4rem;
  color: #898582;
  font-size: 1.2rem;
  border-radius: 1rem;
}

.rules {
  padding: 0.6rem;
  border: 1px solid #000;
  border-radius: 0.6rem;
}
</style>
